

; flags 1
WC = 1  ; water cycle
CL = 2  ; clouds

; flags 2
BANKMASK = 7 ; bitmask for bank spec
EMPHMASK = $E0
R = $20<<8
G = $40<<8
B = $80<<8
BANK0 = 0
BANK1 = 1<<8
BANK2 = 2<<8
BANK3 = 3<<8
BANK4 = 4<<8
BANK5 = 5<<8
BANK6 = 6<<8

; scene id's
_nullscene = 0
_field1 = 2
_castle1 = 4
_sprites1 = 6

;			 			_nullscene 	_field1			_castle1		_sprites1
snam: 	   .dw	0,				testnam1, 		testnam2,	namspr3
spalbg:		.dw	0,				testpalbg,  	palbg3,		palspr3
spalspr:		.dw	0,				testpalspr, 	testpalspr, palspr3
schrbg:		.dw	0,				chrbg,      	chrbg,		chrspr3nam
schrspr:		.dw	0,				chrspr3,     	chrspr3,		chrspr3
sflags:		.dw	0,				BANK0|WC|CL,	BANK0|R,		BANK0


macro sceneword label
	pha
	ldx SCENE
	lda label+1,x
	pha
	lda label,x
	vmnext
endm

macro sceneflag mask
	pha
	ldx SCENE
	lda sflags,x
	and #mask
	vmnext
endm

macro sceneflag2 mask
	pha
	ldx SCENE
	lda sflags+1,x
	and #mask
	vmnext
endm

scenenam:	sceneword snam
scenepalbg:	sceneword spalbg
scenepalspr:	sceneword spalspr
scenechrbg:	sceneword schrbg
scenechrspr:	sceneword schrspr
clouds_enabled:	sceneflag CL
watercycle_enabled:	sceneflag WC
scenebank:	sceneflag2 BANKMASK
sceneemph:  sceneflag2 EMPHMASK



load_scene:  ; n --
	colon
	.dw lit, SCENE, store
	.dw forceblank

	.dw scenebank, bankswitch
	; load nametable
	.dw scenenam,twolit,$2000,decompress_tiles
	; copy chr data to chr ram
	.dw scenechrspr,twolit,$0000,decompress_tiles
	.dw scenechrbg,twolit,$1000,decompress_tiles
	; load palettes
	.dw scenepalbg,astore,twolit,PAL_BUF,lit,16,move
	.dw scenepalspr,astore,twolit,PAL_BUF+$10,lit,16,move

	.dw lit,PPU_MASK_VAR,fetch,lit,$1f,andd
	.dw sceneemph,or,set_ppu_mask

	.dw exit
